<template>
  <div class="content-div">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <div class="msg-item-box" v-for="(item, index) in list" :key="index">
        <div class="msg-content-box" @click="checkVisitor(item, 'productEdit')">
          <div class="msg-name-box">
            <span>{{item.visitor_name}}</span>
            <div v-if="item.is_visitor == '1'" :style="{'background-color' : item.visitor_sex == '男' ? '#1989fa' : '#FF80C0'}">
              <img v-if="item.visitor_sex == '男'" src="@/assets/images/icon-man.png" alt="" srcset="">
              <img v-if="item.visitor_sex == '女'" src="@/assets/images/icon-woman.png" alt="" srcset="">
            </div>
          </div>
          <div class="msg-content">年龄：{{item.is_visitor == '1' ? item.visitor_age : '未满18岁'}}</div>
          <div class="gn-btn-box">
            <div @click="toEdit(item)">
              <van-icon name="edit" />
              <span>编辑</span>
            </div>
            <div @click="deleteObj(item)">
              <van-icon name="delete-o" />
              <span>删除</span>
            </div>
          </div>
        </div>
      </div>
    </van-list>
    <div class="add-btn-box">
      <div @click="$router.push('/patientEdit')">
        <van-icon name="plus" />
        <span>添加就诊人</span>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast, Dialog } from 'vant'
import { selectMedicalVisitorList, deleteVisitor } from '@/api/medical.js'
export default {
  name: 'index',
  data () {
    return {
      loading: false,
      finished: false,
      list: [],
      queryInfo: this.$route.query
    }
  },
  created () {},
  methods: {
    toEdit (data) {
      this.$router.push({
        path: '/patientEdit',
        query: {
          id: data.id
        }
      })
    },
    onLoad () {
      selectMedicalVisitorList({
        member_id: this.$store.state.user.token
      }).then(res => {
        if (res.data.errcode === 0) {
          this.list = res.data.data
          this.loading = false
          this.finished = true
        }
      })
    },
    deleteObj (data) {
      Dialog.confirm({
        title: '提示',
        message: '确定删除选中就诊人？'
      }).then(() => {
        deleteVisitor({
          id: data.id
        }).then(res => {
          if (res.data.errcode === 0) {
            Toast.success('删除成功')
            this.onLoad()
          }
        })
      })
    },
    checkVisitor (item, url) { // 预约跳到此页面选择某个就诊人
      if (this.$route.query.give_service_type) { // 如果是从预约页面点击过来的即可点击进行选择，否则不可以点击整条
        this.$router.replace({
          path: url,
          query: Object.assign({}, this.$route.query, { visitor_id: item.id, visitor_name: item.visitor_name })
        })
      }
    }
  },
  mounted () {}
}
</script>

<style scoped lang="less">
  .content-div{
    font-size: 12px;
    background-color: #F8F8F8;
    min-height: 100%;
    padding: 10px 0 50px;
    position: relative;
    box-sizing: border-box;
    .msg-item-box{
      width: 300px;
      margin-left: 10px;
      box-sizing: border-box;
      padding: 10px;
      background-color: #FFFFFF;
      margin-bottom: 10px;
      border-radius: 6px;
      .msg-content-box{
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        width: 100%;
        .msg-name-box{
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          align-items: center;
          width: 100%;
          span:last-child{
            font-size: 10px;
          }
          div{
            width: 18px;
            height: 18px;
            border-radius: 50%;
            margin-left: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            img{
              width: 10px;
              height: 10px;
              vertical-align: middle;
            }
          }
        }
        .msg-content{
          width: 100%;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          word-break: break-all;
          padding-top: 4px;
          border-bottom: 1px solid #DDDDDD;
          padding-bottom: 10px;
          color: #999999;
        }
        .gn-btn-box{
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          align-items: center;
          padding-top: 10px;
          div:first-child{
            padding-right: 20px;
            color: #07C160;
          }
          div:last-child{
            padding-right: 20px;
            color: #FF0000;
          }
        }
      }
    }
    .add-btn-box{
      position: fixed;
      // bottom: 50px; // 不显示底部tabbar暂时注释掉，需要的时候解开即可
      bottom: 0px;
      left: 0;
      width: 100%;
      height: 50px;
      box-sizing: border-box;padding: 6px;
      background-color: #FFFFFF;
      box-shadow: 0 0 10px 0 #CCCCCC;
      div{
        background-color: #1989fa;
        height: 38px;
        border-radius: 6px;
        line-height: 38px;
        text-align: center;
        color: #FFFFFF;
      }
    }
  }
</style>
